<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
	 <meta charset="utf-8">
	 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	 <title th:replace="common/base::pagetitle"></title>
	 <link th:replace="common/base::static"/>
</head>
<body style="background-color: #f2f2f2;">

<div id="kPage" class="layui-fluid" style="padding: 0">
	 <div class="layui-row">
		  <!-- 主要内容块 -->
		  <div class="layui-col-md12" id="kMainContentCol">
				<div class="layui-fluid wlb-fluid-padding15">
					 <div class="layui-card">
						  <form>
								<div class="layui-form layui-card-header wlb-card-header-auto">
									 <div class="layui-form-item">
										  <div class="layui-inline">
												<label class="layui-form-label">凭证编号</label>
												<div class="layui-input-inline">
													 <input type="text" name="id" placeholder="请输入" autocomplete="off" class="layui-input">
												</div>
										  </div>
										  <div class="layui-inline">
												<label class="layui-form-label">合同编号</label>
												<div class="layui-input-inline">
													 <input type="text" name="contractNo" placeholder="请输入" autocomplete="off" class="layui-input">
												</div>
										  </div>
										  <div shiro:hasAnyRoles="admin, core" class="layui-inline">
												<label class="layui-form-label">供应商</label>
												<div class="layui-input-inline">
													 <select name="supplierId" class="form-control" >
														  <option value="">请选择供应商</option>
														  <option th:each="supplier:${supplierList}" th:value="${supplier.id}" th:text="${supplier.name}"></option>
													 </select>
												</div>
										  </div>
										  <div shiro:hasAnyRoles="admin, supplier" class="layui-inline">
												<label class="layui-form-label">核心企业</label>
												<div class="layui-input-inline">
													 <select name="coreEnterpriseId" class="form-control" >
														  <option value="">请选择核心企业</option>
														  <option th:each="core:${coreList}" th:value="${core.id}" th:text="${core.name}"></option>
													 </select>
												</div>
										  </div>
<!--										  <div shiro:hasAnyRoles="admin" class="layui-inline">-->
<!--												<label class="layui-form-label">归属行</label>-->
<!--												<div class="layui-input-inline">-->
<!--													 <select name="bankId" class="form-control" >-->
<!--														  <option value="">请选择归属行</option>-->
<!--														  <option th:each="bank:${bankList}" th:value="${bank.id}" th:text="${bank.name}"></option>-->
<!--													 </select>-->
<!--												</div>-->
<!--										  </div>-->
										  <div class="layui-inline">
												<label class="layui-form-label">状态</label>
												<div class="layui-input-inline">
													 <select name="status" id="status" class="form-control" xm-select="status" xm-select-skin="normal">
														  <option value="">请选择状态</option>
														  <!-- 默认全部选中 -->
														  <option th:each="dict:${dictList}" th:value="${dict.code}" th:text="${dict.name}"></option>
													 </select>
												</div>
										  </div>
										  
										  <div class="layui-inline">
												<label class="layui-form-label">生成时间</label>
												<div class="layui-input-inline">
													 <input type="text" id="createDate" name="createDate" placeholder="请选择生成时间" autocomplete="off" class="layui-input">
												</div>
										  </div>
<!--										  <div class="layui-form-item layui-hide">-->
<!--												<input type="text" id="status" name="status" value="02,12,22," placeholder="保存ID" autocomplete="off" class="layui-input">-->
<!--										  </div>-->
										  <div class="layui-inline">
												<button class="layui-btn " lay-submit="" lay-filter="kTableSearchFilter">
													 <i class="layui-icon layui-icon-search"></i>
												</button>
												<button class="layui-btn " type="reset">
													 <i class="layui-icon layui-icon-refresh-1"></i>
												</button>
										  </div>
									 </div>
								</div>
						  </form>
						  
						  <div class="layui-card-body">
								<table id="kContentTable" lay-filter="kContentTable"></table>
						  </div>
					 </div>
				
				</div>
		  </div>
	 </div>
</div>

<script th:replace="common/base::context"></script>
<script th:replace="common/base::mainjs"></script>

<script type="text/html" id="coreEnterpriseIdTpl">
	 {{# var data = wlbKit.get(api.sys.getDept + d.coreEnterpriseId).data; }}
	 {{# return data ? data.name : '<span class="layui-badge-rim">未分配</span>'; }}
</script>
<script type="text/html" id="supplierIdTpl">
	 {{# var data = wlbKit.get(api.sys.getDept + d.supplierId).data; }}
	 {{# return data ? data.name : '<span class="layui-badge-rim">未分配</span>'; }}
</script>
<script type="text/html" id="bankIdTpl">
	 {{# var data = wlbKit.get(api.sys.getDept + d.bankId).data; }}
	 {{# return data ? data.name : '<span class="layui-badge-rim">未分配</span>'; }}
</script>
<script type="text/html" id="statusTpl">
	 {{# var data = wlbKit.get(api.sys.dictGetByCode + d.status).data; }}
	 {{# return data ? data.name : '<span class="layui-badge-rim">未知</span>'; }}
</script>

<!--头部工具栏模板-->
<script type="text/html" id="headToolbarTpl">
</script>

<!--表格行工具栏模板-->
<script type="text/html" id="rowToolbarTpl">
	 <a shiro:hasPermission="esign:query:getSignersView" class="layui-btn layui-btn-xs" lay-event="signers"><i class="layui-icon layui-icon-release"></i>签章详情</a>
	 {{#  if(d.status == '31' || d.status == '33' || d.status == '34'){ }}
		  <a shiro:hasPermission="esign:query:downFlowDoc" class="layui-btn layui-btn-warm layui-btn-xs" lay-event="down"><i class="layui-icon layui-icon-release"></i>文件下载</a>
		  <a shiro:hasPermission="esign:query:checkView" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="check"><i class="layui-icon layui-icon-release"></i>查证</a>
	 {{# } }}
</script>

<script type="text/javascript" th:inline="javascript">
    layui.use(['element', 'form', 'layer', 'table','formSelects','laydate'], function () {
        var elemet = layui.element, form = layui.form, layer = layui.layer, table = layui.table, formSelects = layui.formSelects, laydate = layui.laydate;
        var tableId = 'kContentTable';

        laydate.render({
            elem: '#createDate' //指定元素
            //,type: 'date' //默认，可不填
            , format: 'yyyy-MM-dd'
        });

        // 实例化table
        var tableIns = table.render($.extend(config.layui.table, {
            elem: '#' + tableId
            , url: BASE_WEB + 'voucher/list/data' //数据接口
            //, toolbar: '#headToolbarTpl'
				, where: {'status': '03,31,33,34'}
            , cols: [[ //表头
                {type: 'checkbox', fixed: 'left'}
                , {field: 'id', title: '凭证编号', width: 150}
                , {field: 'contractNo', title: '合同编号', width: 120}
                , {field: 'voucherAmount', title: '凭证金额', width: 100}
                , {field: 'coreEnterpriseId', title: '核心企业',  width: 120, templet: '#coreEnterpriseIdTpl'}
                , {field: 'supplierId', title: '供应商', width: 120, templet: '#supplierIdTpl'}
                , {field: 'bankId', title: '银行', width: 120, templet: function (d){
								if (d.bankId != null && d.bankId != ''){
									 var data = wlbKit.get(api.sys.getDept + d.bankId).data;
									 return data ? data.name : '<span class="layui-badge-rim">未知</span>'
								}else{
								    return '<span class="layui-badge-rim">未分配</span>';
								}
						  }}
                , {field: 'signFlowId', title: '签章流程ID', width: 120}
                , {field: 'status', title: '状态', width: 140, templet: '#statusTpl'}
                , {field: 'createDate', title: '生成时间', sort: true, width: 180}
                , {field: 'updateDate', title: '更新时间', sort: true, width: 180}
                , {field: '', title: '操作', width: 285, fixed: 'right', templet: '#rowToolbarTpl'}
            ]]
				,done: function (res, curr, count){
    				var that = this.elem.next();
    				res.data.forEach(function (item, index){
						 if ("04" == item.status) {
						     var tr = that.find(".layui-table-box tbody tr[data-index='"+index+"']").find("td[data-field='status']").css("color", "#ff3300");
						 }else if("90" == item.status){
                       var tr = that.find(".layui-table-box tbody tr[data-index='"+index+"']").find("td[data-field='status']").css("color", "#66cc33");
						 }
					})
				}
		  }));

        var area = ['80%', '60%'];


        // 表格行按钮 监听事件
        table.on('tool(' + tableId + ')', function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            if (layEvent === 'edit') {
                layer.open({
                    type: 2
                    , title: '详情'
                    //, content: BASE_WEB + 'voucher/detail' + '?id=' + data.id
                    , content: BASE_WEB + 'data/preview' + '?id=' + data.id + '&url=voucher/get'
                    , maxmin: true
                    , area: area   // 宽高
                    , btn: ['关闭']
                });
            }
            if (layEvent === 'signers') {
                layer.open({
                    type: 2
                    , title: '签章详情'
                    , content: BASE_WEB + 'esign/query/getSignersView?flowId=' + data.signFlowId
                    , maxmin: true
                    , area: ['80%', '50%']   // 宽高
                    , btn: ['关闭']
                    , end: function (){
                        table.reload(tableId);
                    }
                });
            }
            if (layEvent === 'check') {
                layer.open({
                    type: 2
                    , title: '查证上链信息'
                    , content: BASE_WEB + 'esign/query/checkView?flowId=' + data.signFlowId
                    , maxmin: true
                    , area: ['80%', '50%']   // 宽高
                    , btn: ['关闭']
                    , end: function (){
                        table.reload(tableId);
                    }
                });
            }
            if (layEvent === 'down') {
                wlbKit.get(BASE_WEB + 'esign/query/downFlowDoc?flowId=' + data.signFlowId, null, function (r) {
                    if (r.code === req.status.ok) {
                        console.log(JSON.stringify(r.data))
                        $(r.data.docs).each(function (i,o){
                            window.open(o.fileUrl);
                        })
                    } else {
                        wlbKit.errorMsg(r.msg);
                    }
                });
            }

        });

        // 监听查询
        form.on('submit(kTableSearchFilter)', function (obj) {
            var params = obj.field;
            log('seach=', params);//
            tableIns.reload({
                where: params,
                page: {curr: 1}
            });
            return false;
        });

        // 绑定监听回车事件
        wlbKit.bindEnterEventForLayuiForm();
			
    });

</script>

</body>
</html>